<template>
    <div>
        <!-- 左 -->
        <!-- 公司 -->
        <div class="Headl">
            <el-input placeholder="输入关键字进行过滤" prefix-icon="el-icon-search" v-model="filterText" clearable> </el-input>
            <el-tree
                @node-click="handleNodeClick"
                class="filter-tree"
                :data="data"
                :props="defaultProps"
                default-expand-all
                :filter-node-method="filterNode"
                ref="tree"
            >
            </el-tree>
        </div>
        <!-- 右 -->
        <div class="Headr">
            <div v-if="Head">
                <!-- 客户名称 -->
                <div class="Cusname">
                    <span style="margin-right: 10px">用户名称</span>
                    <span>
                        <el-input v-model="form.userName" placeholder="请输入用户名称" style="width: 220px"></el-input>
                    </span>
                </div>
                <!-- 客户名称 -->
                <div class="Cusname">
                    <span style="margin-right: 10px">手机号码</span>
                    <span>
                        <el-input v-model="form.phonenumber" placeholder="请输入手机号码" style="width: 220px"></el-input>
                    </span>
                </div>
                <!-- 客户类别 -->
                <div class="Cusgory">
                    <span style="margin-right: 10px">状态</span>
                    <el-select v-model="form.status" placeholder="用户状态">
                        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                </div>
            </div>
            <!-- 时间 -->
            <div style="width: 100%; float: left" v-if="Head">
                <div class="Date">
                    <span style="margin-right: 10px">创建时间</span>
                     <el-date-picker
                        v-model="dateRange"
                        type="daterange"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        value-format="yyyy-MM-dd"
                    >   
                    </el-date-picker>
                </div>
                <div class="But">
                    <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
                    <el-button icon="el-icon-refresh" @click="Reset">重置</el-button>
                </div>
            </div>
            <div style="width: 100%; margin-top: 10px; float: left">
                <div style="float: left">
                    <el-button type="primary" icon="el-icon-plus" plain @click="dialogVisible = true">新增</el-button>
                    <el-button type="success" icon="el-icon-edit" disabled>修改</el-button>
                    <el-button type="danger" icon="el-icon-delete" disabled>删除</el-button>
                    <el-button type="info" icon="el-icon-download" plain>导入</el-button>
                    <el-button type="warning" icon="el-icon-download" plain>导出</el-button>
                </div>
                <div style="float: right">
                    <el-tooltip class="item" effect="dark" content="隐藏搜索" placement="top">
                        <el-button icon="el-icon-search" circle @click="Display"></el-button>
                    </el-tooltip>
                    <el-tooltip class="item" effect="dark" content="刷新" placement="top">
                        <el-button icon="el-icon-refresh" circle @click="Reset"></el-button>
                    </el-tooltip>
                    <el-tooltip class="item" effect="dark" content="显隐列" placement="top">
                        <el-button icon="el-icon-menu" circle></el-button>
                    </el-tooltip>
                </div>
            </div>
            <!-- 表 -->
            <el-table
                :data="tableData.slice((page.pageNum - 1) * page.pageSize, page.pageNum * page.pageSize)"
                class="content biao"
                :cell-style="rowClass"
                :header-cell-style="headClass"
            >
                <el-table-column label="用户编号" width="100" type="index" :index="indexMethod"></el-table-column>
                <el-table-column prop="nickName" label="用户名称" width="100"></el-table-column>
                <el-table-column prop="createBy" label="登录名" width="160"></el-table-column>
                <el-table-column prop="name" label="所属机构" width="160"></el-table-column>
                <el-table-column prop="remark" label="所属角色" width="100"></el-table-column>
                <el-table-column prop="phonenumber" label="手机号码" width="180"></el-table-column>
            </el-table>
            <div class="block" style="margin-bottom: 20px; margin-top: 5px">
                <el-pagination
                    background
                    style="float: right"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="page.pageNum"
                    :page-sizes="[10, 20, 30, 50]"
                    :page-size="page.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="10"
                >
                </el-pagination>
            </div>
        </div>
        <!-- 添加框 -->
        <el-dialog title="添加用户" :visible.sync="dialogVisible" width="40%" :before-close="handleClose">
            <el-form :inline="true" :model="formInline" class="demo-form-inline" style="height: 300px">
                <span style="color: red; line-height: 40px; float: left">*</span>
                <el-form-item label="用户昵称" style="float: left">
                    <el-input v-model="formInline.user" placeholder="请输入用户昵称"></el-input>
                </el-form-item>
                <el-form-item label="归属机构" style="float: right">
                    <el-select v-model="value" multiple placeholder="请选择">
                        <el-option v-for="item in data" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="手机号码">
                    <el-input v-model="formInline.user" placeholder="请输入手机号码"></el-input>
                </el-form-item>
                <el-form-item label="邮箱" style="float: right">
                    <el-input v-model="formInline.user" placeholder="请输入邮箱"></el-input>
                </el-form-item>
                <div>
                    <span style="color: red; line-height: 40px; float: left">*</span>
                    <el-form-item label="登录名" style="float: left">
                        <el-input v-model="formInline.user" placeholder="请输入登录名"></el-input>
                    </el-form-item>
                </div>
                <div style="float: right">
                    <span style="color: red; line-height: 40px">*</span>
                    <el-form-item label="用户密码" style="float: right">
                        <el-input v-model="formInline.user" placeholder="请输入用户密码" show-password></el-input>
                    </el-form-item>
                </div>
                <div style="float: left">
                    <el-form-item label="用户性别" style="float: left">
                        <el-select v-model="value" placeholder="请选择">
                            <el-option v-for="item in sex" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                        </el-select>
                    </el-form-item>
                </div>
                <div style="float: right">
                    <el-form-item label="状态" style="float: right">
                        <el-radio v-model="radio" label="1">正常</el-radio>
                        <el-radio v-model="radio" label="2">停用</el-radio>
                    </el-form-item>
                </div>
                <div style="float: left">
                    <el-form-item label="岗位" style="float: left">
                        <el-select v-model="value1" multiple placeholder="请选择">
                            <el-option v-for="item in post" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                        </el-select>
                    </el-form-item>
                </div>
                <div style="float: right">
                    <el-form-item label="角色" style="float: left">
                        <el-select v-model="value2" multiple placeholder="请选择">
                            <el-option v-for="item in post" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                        </el-select>
                    </el-form-item>
                </div>
                <div style="width: 100%; float: left">
                    <el-form-item label="归属仓储客户" style="float: left; width: 100%">
                        <el-input :disabled="true" placeholder="请输入归属仓储客户" style="widht: 100%">
                            <el-button slot="append">选择</el-button>
                        </el-input>
                    </el-form-item>
                </div>
                <div style="width：100%">
                    <el-form-item label="备注" style="float: left">
                        <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="textarea"> </el-input>
                    </el-form-item>
                </div>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
            </div>
        </el-dialog>
        <!-- 上传框 -->
        <!-- <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
            </span>
        </el-dialog> -->
    </div>
</template>

<script>
import { addDateRange } from '../common/ruoyi';
import {listCompose} from '../../api/user'
export default {
    watch: {
        filterText(val) {
            this.$refs.tree.filter(val);
        }
    },

    data() {
        return {
            dateRange: [],
            value1: '',
            input: '',
            filterText: '',
            tableData: [],
            deptId: 100,
            dialogVisible: false,
            radio: '1',
            textarea: '',
            formInline: {
                user: '',
                region: ''
            },
            sex: [
                {
                    value: '选项1',
                    label: '男'
                },
                {
                    value: '选项2',
                    label: '女'
                },
                {
                    value: '选项3', 
                    label: '未知'
                }
            ],
            value: '',
            data: [
                {
                    id: 1,
                    label: '大智若愚科技',
                    deptId: 100,
                    children: [
                        {
                            id: 4,
                            label: '深圳总公司',
                            deptId: 101,
                            children: [
                                {
                                    id: 9,
                                    deptId: 104,
                                    label: '市场部门'
                                },
                                {
                                    id: 10,
                                    deptId: 105,
                                    label: '测试部门'
                                },
                                {
                                    id: 11,
                                    deptId: 106,
                                    label: '财务部门'
                                },
                                {
                                    id: 12,
                                    deptId: 103,
                                    label: '研发部门'
                                }
                            ]
                        }
                    ]
                },
                {
                    id: 2,
                    deptId: 102,
                    label: '长沙分公司',
                    children: [
                        {
                            id: 5,
                            deptId: 108,
                            label: '市场部门'
                        },
                        {
                            id: 6,
                            deptId: 109,
                            label: '财务部门'
                        }
                    ]
                },
                {
                    id: 3,
                    deptId: 107,
                    label: '运维部门'
                }
            ],
            // 客户类别
            options: [
                {
                    value: '选项1',
                    label: '正常'
                },
                {
                    value: '选项2',
                    label: '停用'
                }
            ],
            // 岗位
            post: [
                {
                    value: '选项1',
                    label: '董事长'
                },
                {
                    value: '选项2',
                    label: '项目经理'
                },
                {
                    value: '选项3',
                    label: '人力资源'
                },
                {
                    value: '选项4',
                    label: '普通员工'
                }
            ],
            // 角色
            post: [
                {
                    value: '选项1',
                    label: '普通角色'
                },
                {
                    value: '选项2',
                    label: '保洁阿姨'
                },
                {
                    value: '选项3',
                    label: '普通管理员'
                },
                {
                    value: '选项4',
                    label: '角色名称'
                }
            ],
            value1: [],
            value2: [],
            defaultProps: {
                children: 'children',
                label: 'label'
            },
            // 分页
            page: {
                pageSize: 10,
                pageNum: 1
            },
            form:{
                userName:'',
                phonenumber:'',
                status:''
            },
            Head: true
        };
    },
    methods: {
        onSubmit() {
            console.log('submit!');
        },
        filterNode(value, data) {
            if (!value) return true;
            console.log(data);
            return data.label.indexOf(value) !== -1;
        },
        // 分页
        handleSizeChange(val) {
            this.page.pageSize = Number(val);
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            this.page.pageNum = Number(val);
            console.log(`当前页: ${val}`);
        },
        // 分页点击
        indexMethod(index) {
            return (this.page.pageNum - 1) * this.page.pageSize + index + 1;
        },
        // 表头样式设置
        headClass() {
            return 'text-align: center;background:#F8F8F9;color:#515A6D';
        },
        // 表格样式设置
        rowClass() {
            return 'text-align: center;';
        },
        // 页面渲染
        handleNodeClick(data) {
            this.$axios
                .get('http://47.100.8.204:8092/system/user/list', {
                    pageSize: this.page.pageSize,
                    deptId: data.deptId
                    // 'deptld':this.deptld
                })
                .then((res) => {
                    this.tableData = res.data.rows;
                    console.log(res);
                });
        },
        //   添加矿
        handleClose(done) {
            this.$confirm('确认关闭？')
                .then((_) => {
                    done();
                })
                .catch((_) => {});
        },
        // 重置
        Reset() {
            this.handleNodeClick(this.deptId);
        },
        // 表头显示
        Display() {
            this.Head = !this.Head;
        },
        search(){
            listCompose(addDateRange(this.form,this.dateRange)).then((res)=>{
                console.log(res);
                this.tableData=res.rows
            })
        }
    },
    mounted() {
        this.handleNodeClick(this.deptId);
        
    }
};
</script>

<style scoped>
.Headl {
    width: 16.6666666667%;
    float: left;
}
.Headr {
    float: left;
    width: 82%;
    margin-left: 10px;
}
/* 客户类别 */
.Cusgory {
    height: 100%;
    float: left;
    margin-right: 10px;
}
.Cusgory span {
    display: block;
    height: 100%;
    line-height: 30px;
    font-weight: 800;
    color: #606266;
    float: left;
}
/* 客户名称 */
.Cusname {
    height: 100%;
    float: left;
    margin-right: 10px;
}
.Cusname span {
    display: block;
    height: 100%;
    line-height: 30px;
    font-weight: 800;
    color: #606266;
    float: left;
}
.Date {
    float: left;
    margin-top: 10px;
}
.Date span {
    display: block;
    height: 100%;
    line-height: 30px;
    font-weight: 800;
    color: #606266;
    float: left;
}
.But {
    height: 100%;
    float: left;
    margin-left: 10px;
}
.But button {
    margin-top: 10px;
}
.content {
    padding: 1px;
    /* background: #f8f8f9; */
    font-size: 13px;
    text-align: center !important;
    color: #515a6d !important;
    top: 10px;
}
/deep/.el-table__header {
    width: 100% !important;
}
/deep/.el-table__body {
    width: 100% !important;
}
/deep/. {
    clear: both;
}
</style>